﻿namespace Okazuki.BehaviorSupport.Design.Commons
{
    using System;
    using System.Collections.Generic;
    using System.Windows;
    using System.Linq;

    /// <summary>
    /// ActionSelectWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class ActionSelectWindow : Window
    {
        public ActionSelectWindow(IEnumerable<Type> triggerTypes, IEnumerable<Type> actionTypes)
        {
            InitializeComponent();
            this.comboBoxTriggers.ItemsSource = triggerTypes;
            this.comboBoxTriggers.SelectedItem = triggerTypes
                .Where(t => t.FullName == TypeNames.EventTrigger)
                .FirstOrDefault();
            this.listBoxActions.ItemsSource = actionTypes;
        }

        public Tuple<Type, Type> SelectedTriggerAndAction
        {
            get
            {
                var triggerType = this.comboBoxTriggers.SelectedItem as Type;
                var actionType = this.listBoxActions.SelectedItem as Type;
                if (triggerType == null || actionType == null)
                {
                    return null;
                }
                return new Tuple<Type, Type>(triggerType, actionType);
            }
        }

        private void buttonOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}
